package com.qdxwx.data.service.book;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.data.mapper.book.BookRequireMapper;
import com.qdxwx.models.book.BookRequire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

/**
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Service
public class BookRequireServiceImpl implements BookRequireService {

    @Autowired
    private BookRequireMapper bookRequireMapper;

    @Override
    public int insert(BookRequire bookRequire) {
        bookRequire.setCreateTime(LocalDateTime.now());
        return bookRequireMapper.insertBookRequire(bookRequire);
    }

    @Override
    public BookRequire get(int id) {
        if (id < 1) return null;
        return bookRequireMapper.selectById(id);
    }

    @Override
    public List<BookRequire> getList(BookRequire bookRequire, PageRequest page) {
        return bookRequireMapper.selectList(bookRequire, page);
    }

    @Override
    public int count(BookRequire bookRequire) {
        return bookRequireMapper.count(bookRequire);
    }

    @Override
    public int update(BookRequire bookRequire) {
        if (bookRequire.getId() < 1) return 0;
        bookRequire.setUpdateTime(LocalDateTime.now());
        return bookRequireMapper.updateBookRequire(bookRequire);
    }

    @Override
    public int delete(int id) {
        if (id < 1) return 0;
        return bookRequireMapper.deleteById(id);
    }

}
